// 导包
import instance from "@/utils/axios.js";

// 获取频道列表
const getChannelList = (() => {
    return instance({
        url: '/v1_0/channels',
        method: "get"
    })
})

export { getChannelList }


const getArticles = (({ channel_id, timestamp }) => {
    return instance({
        url: '/v1_1/articles',
        method: 'get',
        params: { channel_id, timestamp, with_top: 1 }
    })
})
export { getArticles }


//3.获取文章详细信息
const getArticleInfo = id => {
    return instance({
        //这个接口的id直接在路径后面拼接  格式： url/id
        url: `/v1_0/articles/${id}`,
        method: 'get',
    })
}
//导出接口
export { getArticleInfo }

// 关注和取消关注
const deleteFollowing = target => {
    return instance({
        url: `/v1_0/user/followings/${target}`,
        method: 'DELETE',
    })
}

const addFollowing = ({ target }) => {
    return instance({
        url: '/v1_0/user/followings',
        method: 'post',
        data: { target }
    })
}
export { addFollowing, deleteFollowing }

// 点赞和取消点赞
const deleteLikings = target => {
    return instance({
        url: `/v1_0/article/likings/${target}`,
        method: 'DELETE',
    })
}

const addLikings = ({ target }) => {
    return instance({
        url: '/v1_0/article/likings',
        method: 'post',
        data: { target }
    })
}
export { deleteLikings, addLikings }


// 喜欢和不喜欢
const notLick = ({ target }) => {
    return instance({
        url: '/v1_0/article/dislikes',
        method: 'post',
        data: { target }
    })
}

const deleteLick = target => {
    return instance({
        url: `/v1_0/article/dislikes/${target}`,
        method: 'DELETE',
    })
}
export { notLick, deleteLick }

// 搜索

const searchSuggestionList = q => {
    return instance({
        url: '/v1_0/suggestion',
        method: 'get',
        params: { q }
    })
}
export { searchSuggestionList }


// 获取搜索结果
const getSearchList = (params) => {
    return instance({
        url: '/v1_0/search',
        method: 'get',
        params
    })
}
export { getSearchList }

// 获取用户搜索历史
const getSearchAll = () => {
    return instance({
        url: '/v1_0/search/histories',
        method: 'get',

    })
}
export { getSearchAll }


//删除用户搜索历史

const deleteSearchAll = () => {
    return instance({
        url: '/v1_0/search/histories',
        method: 'DELETE',

    })
}
export { deleteSearchAll }